package demo.database.H2.D01_功能测试;


import java.sql.Connection;

import org.h2.jdbcx.JdbcConnectionPool;

import com.titan.core.utils.db.DBUtils;
import com.titan.core.utils.debug.Timer;
import com.titan.core.utils.io.ConsoleUtils;

public class T02_自带连接池 {
    private static void run() throws Exception {
        String url = "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1"; 
        String username = "sa";
        String password = "";
        
        // h2自带的连接池 ， 默认连接池是初始10个连接 
        JdbcConnectionPool cp = JdbcConnectionPool.create(url, username, password); 
        // 通过连接池获取连接 
        Connection conn = cp.getConnection(); 

        ConsoleUtils.log(conn);
        
        DBUtils.close(conn);
    }


    public static void main(String[] args) {
        Timer timer = Timer.$();
        try {
            run();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            timer.print();
        }
    }
}
